#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1e6 + 10;
struct node
{
	int start;
	int end;
}s[N];
int n;
int cmp(node a, node b)
{
	return a.end < b.end;
}
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s[i].start >> s[i].end;
	}
	sort(s, s + n, cmp);
	int pos = 0;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (pos <= s[i].start) {
			pos = s[i].end;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}